package ccm.component.menu;

import ccm.common.Pair;

import java.awt.*;

public final class MenuItemFactory
{
    private MenuItemFactory()
    {
    }

    public static Class<? extends MenuItemJPanel> getMenuItemClass(boolean isArray,ScnsType type)
    {
        if(isArray)
        {
            return ArrayMenuJPanel.class;
        }
        else
        {
            switch(type)
            {
                case SCNS_TYPE_INT8:
                    return Int8MenuItemJPanel.class;
                case SCNS_TYPE_UINT8:
                    return Uint8MenuItemJPanel.class;
                case SCNS_TYPE_INT16:
                    return Int16MenuItemJPanel.class;
                case SCNS_TYPE_UINT16:
                    return Uint16MenuItemJPanel.class;
                case SCNS_TYPE_INT32:
                    return Int32MenuItemJPanel.class;
                case SCNS_TYPE_UINT32:
                    return Uint32MenuItemJPanel.class;
                case SCNS_TYPE_INT64:
                    return Int64MenuItemJPanel.class;
                case SCNS_TYPE_UINT64:
                    return Uint64MenuItemJPanel.class;
                case SCNS_TYPE_FLOAT:
                    return FloatMenuItemJPanel.class;
                case SCNS_TYPE_DOUBLE:
                    return DoubleMenuItemJPanel.class;
                case SCNS_TYPE_FUNCTION:
                    return FunctionMenuItemJPanel.class;
                case SCNS_TYPE_BOOLEAN:
                    return BooleanMenuItemJPanel.class;
                case SCNS_TYPE_ENUM:
                    return EnumMenuItemJPanel.class;
            }
        }
        throw new IllegalArgumentException();
    }

    public static MenuItemJPanel getMenuItem(DelegateSenderInterface sender,Component[] rightMenu,String saveArgPrefix,int dataIndex,boolean canModify,boolean isArray,ScnsType type,int page,String name,Object ex)
    {
        System.out.println("getMenuItem");
        if(isArray)
        {
            return new ArrayMenuJPanel(sender,saveArgPrefix,dataIndex,canModify,type,page,name,ex,rightMenu);
        }
        else
        {
            switch(type)
            {
                case SCNS_TYPE_INT8:
                    return new Int8MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_UINT8:
                    return new Uint8MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_INT16:
                    return new Int16MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_UINT16:
                    return new Uint16MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_INT32:
                    return new Int32MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_UINT32:
                    return new Uint32MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_INT64:
                    return new Int64MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_UINT64:
                    return new Uint64MenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_FLOAT:
                    return new FloatMenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_DOUBLE:
                    return new DoubleMenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_FUNCTION:
                    return new FunctionMenuItemJPanel(sender,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_BOOLEAN:
                    return new BooleanMenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name);
                case SCNS_TYPE_ENUM:
                    return new EnumMenuItemJPanel(sender,rightMenu,saveArgPrefix,dataIndex,canModify,type,page,name,(Integer)ex);
            }
        }
        throw new IllegalArgumentException();
    }

    public static Pair<Object,Integer> decodeInnerDataEx(boolean isArray,ScnsType type,byte[] receiveBuf,int start)
    {
        if(!isArray&&type==ScnsType.SCNS_TYPE_ENUM)
        {
            return EnumMenuItemJPanel.decodeInnerDataEx(receiveBuf,start);
        }
        else if(isArray)
        {
            return ArrayMenuJPanel.decodeInnerDataEx(receiveBuf,start);
        }
        return new Pair<>(null,start);
    }
}
